package com.yanqu.road.server.gameplayer.module.player.beauty;

import com.yanqu.road.entity.config.skill.SkillInfo;
import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.entity.player.BeautyPeerlessSkillInfo;
import com.yanqu.road.entity.player.UserBeauty;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.BeautyModule;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.manger.config.BeautyMgr;
import com.yanqu.road.server.protocol.GameErrorCode;

public class PeerlessSkill extends BeautyUpgradeSkillAction {

    public PeerlessSkill(int beautyId, int position, int skillType, int batch, BeautyModule beautyModule, GamePlayer player) {
        super(beautyId, position, skillType, batch, beautyModule, player);
    }

    @Override
    public void setOldLv() {
        UserBeauty userBeauty = beautyModule.getUserBeauty(beautyId);
        BeautyPeerlessSkillInfo peerlessSkillInfo = userBeauty.getPeerlessSkill(position);
        if (null == peerlessSkillInfo) {
            this.ret = GameErrorCode.E_BEAUTY_PEERLESS_PATRONS_POSITION_ERR;
            return;
        }
        if (peerlessSkillInfo.getPatronsId() == 0) {
            this.ret = GameErrorCode.E_BEAUTY_PEERLESS_PATRONS_EXISTS;
            return;
        }
        oldLv = peerlessSkillInfo.getLevel();
    }

    @Override
    public SkillInfo getSkillInfo() {
        UserBeauty userBeauty = beautyModule.getUserBeauty(beautyId);
        SkillInfo skillInfo = BeautyMgr.getPeerlessSkill(userBeauty, position);
        if (null == skillInfo) {
            this.ret = GameErrorCode.E_BEAUTY_PEERLESS_PATRONS_POSITION_ERR;
        }
        return skillInfo;
    }

    @Override
    public void calConsumer() {
        //无双技能，不支持批量升级
        UserBeauty userBeauty = beautyModule.getUserBeauty(beautyId);
        if (!BeautyMgr.checkPeerlessSkillUpgradeEnough(player, userBeauty, position)) {
            this.ret = GameErrorCode.E_BEAUTY_PEERLESS_SKILL_UP_SKIN_NOTENOUGH;
            return;
        }
        if(batch != 1){
            this.ret = GameErrorCode.E_REQUEST_ARGUMENT_ERROR;
            return;
        }
    }

    @Override
    public void upgrade() {
        preValidArgument();

        if(this.ret == 0){
            calConsumer();
        }
        if(this.ret == 0) {
            UserBeauty userBeauty = beautyModule.getUserBeauty(beautyId);
            userBeauty.updatePeerlessSkillLevel(position, oldLv + 1);
            this.realBatch = 1;
        }
    }
}
